*Required packages
ssc install ftools
ssc install reghdfe
ssc install outreg2

*Set working directory
cd "/path/to/replication"

*Open data
u "data/panel_month_dummies.dta", clear

*Define full set of controls
global FE panelvar timevar b157.timevar#c.foreign_pop b157.timevar#c.educ_diplba
global x_mechanism covid2 losing_income_d extr_right_mayor covid_unemp covid_farright unemp_farright covid_unemp_farright


* Table H3: Test for reporting bias - by far-right mayors


* drop national newspapers / drop individuals 

	su hc_pc_asians_dropnationalmedia if covid2==0 & losing_income_d==0
	local meandv =  round(r(mean), 0.00001)
	reghdfe hc_pc_asians_dropnationalmedia $x_mechanism timevar_losingincome timevar_province, absorb(panelvar timevar  b157.timevar#c.foreign_pop b157.timevar#c.educ_diplba) cluster(panelvar)
	outreg2 using "tableH3.tex", replace tex dec(5) ctitle("Source: Drop", "national media") keep( $x_mechanism) nocons label addtext(Mean DV, `meandv')
	
	su hc_pc_asians_sourcenotindividual if covid2==0 & losing_income_d==0
	local meandv =  round(r(mean), 0.00001)
	reghdfe hc_pc_asians_sourcenotindividual  $x_mechanism timevar_losingincome timevar_province, absorb(panelvar timevar  b157.timevar#c.foreign_pop b157.timevar#c.educ_diplba) cluster(panelvar)
	outreg2 using "tableH3.tex", tex dec(5) ctitle("Source: Drop", "individuals") keep( $x_mechanism) nocons label addtext(Mean DV, `meandv')

* non verbal hate crimes / verbal

	su hc_pc_asians_nonverbal if covid2==0 & losing_income_d==0
	local meandv =  round(r(mean), 0.00001)
	reghdfe hc_pc_asians_nonverbal  $x_mechanism timevar_losingincome timevar_province, absorb(panelvar timevar  b157.timevar#c.foreign_pop b157.timevar#c.educ_diplba) cluster(panelvar)
	outreg2 using "tableH3.tex", tex dec(5) ctitle("Type: Not" "verbal") keep( $x_mechanism) nocons label addtext(Mean DV, `meandv')

	su hc_pc_asians_verbal if covid2==0 & losing_income_d==0
	local meandv =  round(r(mean), 0.00001)
	reghdfe hc_pc_asians_verbal  $x_mechanism timevar_losingincome timevar_province, absorb(panelvar timevar  b157.timevar#c.foreign_pop b157.timevar#c.educ_diplba) cluster(panelvar)
	outreg2 using "tableH3.tex", tex dec(5) ctitle("Type:", "Verbal") keep( $x_mechanism) nocons label addtext(Mean DV, `meandv')

	su hc_pc_asians_violent if covid2==0 & losing_income_d==0
	local meandv =  round(r(mean), 0.00001)
	reghdfe hc_pc_asians_violent  $x_mechanism timevar_losingincome timevar_province, absorb(panelvar timevar  b157.timevar#c.foreign_pop b157.timevar#c.educ_diplba) cluster(panelvar)
	outreg2 using "tableH3.tex", tex dec(5) ctitle("Type:", "Physical") keep( $x_mechanism) nocons label addtext(Mean DV, `meandv')

* individual or groups / institutions, media

	su hc_pc_asians_attacker_person if covid2==0 & losing_income_d==0
	local meandv =  round(r(mean), 0.00001)
	reghdfe hc_pc_asians_attacker_person  $x_mechanism timevar_losingincome timevar_province, absorb(panelvar timevar  b157.timevar#c.foreign_pop b157.timevar#c.educ_diplba) cluster(panelvar)
	outreg2 using "tableH3.tex", tex dec(5) ctitle("Attacker:", "Person") keep( $x_mechanism) nocons label addtext(Mean DV, `meandv')

	su hc_pc_asians_attacker_instit if covid2==0 & losing_income_d==0
	local meandv = round(r(mean), 0.00001)
	reghdfe hc_pc_asians_attacker_instit  $x_mechanism timevar_losingincome timevar_province, absorb(panelvar timevar  b157.timevar#c.foreign_pop b157.timevar#c.educ_diplba) cluster(panelvar)
	outreg2 using "tableH3.tex", tex dec(5) ctitle("Attacker:", "Institutions") keep( $x_mechanism) nocons label addtext(Mean DV, `meandv')
	
* drop social media
	
	su hc_pc_asians_nosocialmedia if covid2==0 & losing_income_d==0
	local meandv =  round(r(mean), 0.00001)
	reghdfe hc_pc_asians_nosocialmedia  $x_mechanism timevar_losingincome timevar_province, absorb(panelvar timevar  b157.timevar#c.foreign_pop b157.timevar#c.educ_diplba) cluster(panelvar)
	outreg2 using "tableH3.tex", tex dec(5) ctitle("Where Not:", "social media") keep( $x_mechanism) nocons label addtext(Mean DV, `meandv')

	
	*pval from randomiz inf
	 randcmd ((covid_unemp_farright) reghdfe hc_pc_asians_nosocialmedia  $x_mechanism timevar_losingincome timevar_province, ///
		absorb(panelvar timevar  b157.timevar#c.foreign_pop b157.timevar#c.educ_diplba) cluster(panelvar)), ///
		treatvars(covid_unemp_farright) reps(500)

	
